//
//  SayHelloView.m
//  ChatForHot
//
//  Created by FLY on 2018/10/18.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "SayHelloView.h"

@implementation SayHelloView

- (instancetype)init{
    
    self = [super init];
    
    if (self) {
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
//        self.alpha = 0.4;
        [self addSubview:self.HOTCHATbackView];
        [self addSubview:self.HOTCHATimgView1];
        [self addSubview:self.HOTCHATimgView2];
        [self addSubview:self.HOTCHATimgView3];
        [self addSubview:self.HOTCHATimgView4];
        [self addSubview:self.HOTCHATimgView5];
        [self addSubview:self.HOTCHATsayHiBtn];
        
        [self.HOTCHATbackView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(25);
            make.right.equalTo(self).offset(-25);
            make.top.equalTo(self.HOTCHATimgView1).offset(-10);
            make.bottom.equalTo(self.HOTCHATsayHiBtn).offset(15);
            make.centerY.equalTo(self);
        }];
        
        [self.HOTCHATimgView1 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(Auto(294));
            make.top.equalTo(self.HOTCHATbackView).offset(10);
            make.left.equalTo(self.HOTCHATbackView).offset(10);
        }];
        [self.HOTCHATimgView2 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(Auto(294));
            make.top.equalTo(self.HOTCHATbackView).offset(10);
            make.right.equalTo(self.HOTCHATbackView).offset(-10);
//            make.left.equalTo(self.HOTCHATimgView1.mas_right).offset(11);
        }];
        
        [self.HOTCHATimgView3 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(Auto(188));
            make.top.equalTo(self.HOTCHATimgView1.mas_bottom).offset(11);
            make.left.equalTo(self.HOTCHATbackView).offset(10);
        }];
        
        [self.HOTCHATimgView4 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(Auto(188));
            make.top.equalTo(self.HOTCHATimgView3.mas_top);
            make.left.equalTo(self.HOTCHATimgView3.mas_right).offset(10);
        }];
        [self.HOTCHATimgView5 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(Auto(188));
            make.top.equalTo(self.HOTCHATimgView4);
            make.right.equalTo(self.HOTCHATbackView).offset(-10);
        }];
        
        [self.HOTCHATsayHiBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.HOTCHATimgView1);
            make.right.equalTo(self.HOTCHATimgView2);
            make.top.equalTo(self.HOTCHATimgView3.mas_bottom).offset(22);
            make.height.mas_equalTo(44);
        }];
    }
    return self;
}
- (void)setDataArr:(NSArray *)dataArr{
    
    _dataArr = dataArr;
    
    [self HOTCHATsetImgView:self.HOTCHATimgView1 Index:1];
    [self HOTCHATsetImgView:self.HOTCHATimgView2 Index:2];
    [self HOTCHATsetImgView:self.HOTCHATimgView3 Index:3];
    [self HOTCHATsetImgView:self.HOTCHATimgView4 Index:4];
    [self HOTCHATsetImgView:self.HOTCHATimgView5 Index:5];
}
- (void)HOTCHATsetImgView:(UIImageView *)imgView Index:(NSInteger)index{
    
    UserInfoModel *model = self.dataArr[index-1];
    
    [imgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",APIHEADER,model.headPic]] placeholderImage:[UIImage imageNamed:@"personal_atatar_but_h"]];
}
-(UIView *)HOTCHATbackView{
    
    if (_HOTCHATbackView == nil) {
        
        _HOTCHATbackView = [[UIView alloc]init];
        _HOTCHATbackView.backgroundColor = [UIColor whiteColor];
        _HOTCHATbackView.layer.masksToBounds = YES;
        _HOTCHATbackView.layer.cornerRadius = 8;
        
    }
    return _HOTCHATbackView;
}
- (UIImageView *)HOTCHATimgView1{
    
    if (_HOTCHATimgView1 == nil) {
        
        _HOTCHATimgView1 = [self HOTCHATinitImgWithIndex:1];
    }
    return _HOTCHATimgView1;
}
- (UIImageView *)HOTCHATimgView2{
    
    if (_HOTCHATimgView2 == nil) {
        
        _HOTCHATimgView2 = [self HOTCHATinitImgWithIndex:2];
    }
    return _HOTCHATimgView2;
}
- (UIImageView *)HOTCHATimgView3{
    
    if (_HOTCHATimgView3 == nil) {
        
        _HOTCHATimgView3 = [self HOTCHATinitImgWithIndex:3];
    }
    return _HOTCHATimgView3;
}
- (UIImageView *)HOTCHATimgView4{
    
    if (_HOTCHATimgView4 == nil) {
        
        _HOTCHATimgView4 = [self HOTCHATinitImgWithIndex:4];
    }
    return _HOTCHATimgView4;
}
- (UIImageView *)HOTCHATimgView5{
    
    if (_HOTCHATimgView5 == nil) {
        
        _HOTCHATimgView5 = [self HOTCHATinitImgWithIndex:5];
    }
    return _HOTCHATimgView5;
}
- (UIImageView *)HOTCHATinitImgWithIndex:(NSInteger)index{
    
    UIImageView * imgView = [[UIImageView alloc] init];
    imgView.layer.cornerRadius = 8;
    imgView.clipsToBounds = YES;
    imgView.contentMode = UIViewContentModeScaleAspectFill;
    imgView.tag = index;
    imgView.userInteractionEnabled = YES;
    imgView.layer.borderWidth = 0.5;
    imgView.layer.borderColor = [UIColor blackColor].CGColor;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(HOTCHATclcikImgViewAction:)];
    [imgView addGestureRecognizer:tap];
    
    return imgView;
}
- (UIButton *)HOTCHATsayHiBtn{
    
    if (_HOTCHATsayHiBtn == nil) {
        _HOTCHATsayHiBtn = [[UIButton alloc]init];
        _HOTCHATsayHiBtn.layer.masksToBounds = YES;
        _HOTCHATsayHiBtn.layer.cornerRadius = 8;
        [_HOTCHATsayHiBtn setTitle:NSLocalizedString(@"StrN056", nil) forState:(UIControlStateNormal)];
        [_HOTCHATsayHiBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _HOTCHATsayHiBtn.titleLabel.font = [UIFont systemFontOfSize:18];
        [_HOTCHATsayHiBtn setBackgroundImage:[UIImage imageWithColor:HOTCHATMainColor] forState:UIControlStateNormal];
        [_HOTCHATsayHiBtn setBackgroundImage:[UIImage  imageWithColor:HOTCHATHexColor(0x8123FF)]  forState:UIControlStateHighlighted];
        [_HOTCHATsayHiBtn addTarget:self action:@selector(HOTCHATsayHiAction) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _HOTCHATsayHiBtn;
}

- (void)HOTCHATsayHiAction{
    
    [self.delegate HOTCHATsayHello];
}
- (void)HOTCHATclcikImgViewAction:(UITapGestureRecognizer *)tap{
    
    [self.delegate HOTCHATclcikTheUserWithIndex:tap.view.tag-1];
}
@end
